package com.ydkj.a37e_mall.Resource.sql;

import android.app.SearchableInfo;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import com.ydkj.a37e_mall.Classes.Model.Request.SearchInfo;


/**
 * Created by Administrator on 2016/12/19.
 */
public class SqliteHelper extends SQLiteOpenHelper {
    //用来保存UserID、Access Token、Access Secret的表名
    public static final String NEWSS_NAME = "mallusers";


    public SqliteHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    //创建表
    @Override
    public void onCreate(SQLiteDatabase db) {
        //建立新人信息表
        db.execSQL("CREATE TABLE IF NOT EXISTS " +
                NEWSS_NAME + "(" +
                SearchInfo.ID + " integer primary key," +
                SearchInfo.NAME + " varchar" +
                ")"
        );


    }

    //更新表
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + NEWSS_NAME);

        onCreate(db);
        Log.e("Database", "onUpgrade");
    }

    //更新列
    public void updateColumn(SQLiteDatabase db, String oldColumn, String newColumn, String typeColumn) {
        try {
            db.execSQL("ALTER TABLE " +
                    NEWSS_NAME + " CHANGE " +
                    oldColumn + " " + newColumn +
                    " " + typeColumn


            );
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
